package com.jzo2o.trade.service.impl;

import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jzo2o.api.trade.dto.request.PayReqDTO;
import com.jzo2o.trade.enums.TradingStateEnum;
import com.jzo2o.trade.mapper.TradingMapper;
import com.jzo2o.trade.model.domain.Trading;
import com.jzo2o.trade.service.ITradingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class TradingServiceImpl extends ServiceImpl<TradingMapper, Trading> implements ITradingService {


    /**
     * 新增交易单
     *
     * @param reqDTO 提交参数
     * @return 交易单
     */
    @Override
    public Trading insertTrading(PayReqDTO reqDTO) {
        Trading trading = new Trading();
        trading.setProductOrderNo(reqDTO.getProductOrderNo());
        trading.setTradingOrderNo(reqDTO.getProductOrderNo() + "" + RandomUtil.randomInt(10, 99));
        trading.setTradingChannel(reqDTO.getTradingChannel().getValue());
        trading.setTradingType(reqDTO.getPayType().getValue());
        trading.setTradingState(TradingStateEnum.ZFBZ.getCode());
        trading.setTradingAmount(reqDTO.getTradingAmount());
        trading.setMemo(reqDTO.getMemo());

        this.save(trading);
        return trading;
    }


}
